package edu.xlh.travel.controller.admin;

import com.alibaba.fastjson.JSONArray;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.Carousel;
import edu.xlh.travel.pojo.Hotel;
import edu.xlh.travel.pojo.querypojo.QueryCarousel;
import edu.xlh.travel.pojo.querypojo.QueryCheckTask;
import edu.xlh.travel.service.CarouselService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RequestMapping("/carousel")
@Controller
@CrossOrigin
public class CarouselController {
    @Autowired
    private CarouselService carouselService;

    @Log("跳转轮播信息列表页面")
    @RequestMapping("/carouselList")
    public String carouselList () {
        return "admin/carouselmanage/carouselList";
    }

    @Log("查找所有轮播信息")
    @RequestMapping("/findAllCarousel")
    @ResponseBody
    public Result findAllCarousel(int page, int limit , HttpSession session) {
        return carouselService.findAllCarousel(page , limit , session);
    }

    /*
     * edit carousel
     * */
    @Log("编辑轮播信息")
    @RequestMapping("/edit/{id}")
    @ResponseBody
    public Result edit(@PathVariable("id")String id , @RequestBody Carousel carousel , HttpSession session) {
        return carouselService.edit(id , carousel , session);
    }

    /*
     * delete carousel by id
     * */
    @Log("根据id删除轮播信息")
    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public Result deleteById(@PathVariable("id") String id , @RequestBody HashMap hashMap , HttpSession session) {
        return carouselService.deleteById(id , hashMap , session);
    }

    /*
     *
     * batch delete
     *  */
    @Log("批量删除轮播信息")
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Result batchDelete(@RequestBody JSONArray jsonArray , HttpSession session) {
        return carouselService.batchDelete(jsonArray ,session);
    }

    /*
     * query carousel by condition
     * */
    @Log("条件模糊查询轮播信息")
    @RequestMapping("/QueryCarouselCondition")
    @ResponseBody
    public Result  QueryCarouselByCondition(Integer page, Integer limit, QueryCarousel queryCarousel , HttpSession session) {
        return carouselService.QueryCarouselByCondition(page , limit ,queryCarousel , session);
    }

    /*
    * add carousel
    * */
    @Log("新增轮播信息")
    @RequestMapping("/add")
    @ResponseBody
    public Result add (@RequestBody Carousel carousel , HttpSession session) {
        return carouselService.add(carousel , session);
    }
}
